﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Atlanchim.Crm.Mui.Helpers
{
    public class FragmentHelper
    {
        public static Dictionary<string, string> Split(string input)
        {
            Dictionary<string, string> result = new Dictionary<string, string>();

            if (!string.IsNullOrEmpty(input))
            {
                //string strRegex = @"(?<Keys>\w+)=(?<Values>\d+)";
                string strRegex = @"(?<Keys>\w+)=(?<Values>\w+)";
                RegexOptions myRegexOptions = RegexOptions.ExplicitCapture;
                Regex myRegex = new Regex(strRegex, myRegexOptions);

                foreach (Match myMatch in myRegex.Matches(input))
                {
                    if (myMatch.Success)
                    {
                        try
                        {
                            string key = myMatch.Groups["Keys"].Value;
                            string value = myMatch.Groups["Values"].Value;
                            result.Add(key, value);
                        }
                        catch
                        {
                            // Todo : Logger
                        }
                    }
                }
            }

            return result;
        }
    }
}
